 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BomberManServer.Gaming.Time
{
    public class Trigger
    {
        private int countdown_max;
        private int countdown;
        public bool bound;
        public bool canceled { get; set; }
        public delegate void actionHandler();
        private actionHandler action;

        public Trigger(int countdown, actionHandler action)
        {
            this.countdown_max = countdown;
            this.countdown = countdown;
            this.action = action;
            canceled = false;
            bound = false;
        }


        public void changeCountdown(int newcountdown)
        {
            this.countdown_max = newcountdown;
        }
        // returns true if we can delete it
        public bool compute()
        {
            // time is running out
            if (countdown == 0)
            {
                if (!canceled)
                    action();
                return true;
            }

            // we need to wait a little more
            countdown--;
            return false;
        }

        public void reset()
        {
            countdown = countdown_max;
            canceled = false;
        }
    }
}
